import {proxyWithdrawInfoApi} from '@/services/api/low-level';

const initState = () => {
  return {
    amount: 0,
    commissionAvg: 0,
    createTime: null,
    creator: '',
    lastUpdate: null,
    leftAmount: 0,
    operator: "",
    proxyId: 0,
    proxyStatus: 0,
  };
};

const getters = {
  isCreditUpAgent: state => {
    return state.proxyStatus === consts.CREDIT_OPEN;
  }
};

// actions
const actions = {
  async [types.GET_CREDIT_STATUS] ({commit}) {
    const [result, data] = await proxyWithdrawInfoApi();

    if (result) {
      commit(types.GET_CREDIT_STATUS_SUCCESS, data);
    }

    return {result, data};
  },
};

// mutations
const mutations = {
  [types.GET_CREDIT_STATUS_SUCCESS] (state, data) {
    Object.assign(state, data);
  }
};

export default {
  state: initState,
  getters,
  actions,
  mutations,
};
